A = input()
B = input()
n = int(input())
m = []
for _ in range(n):
    m.append(list(map(int,input().split())))

dp = [[0 for _ in range(len(A))] for _ in range(len(B))]
for i in range(len(B)):
    for j in range(len(A)):
        if A[j] == B[i]:
            dp[i][j] = 1
dyp = []
for c in range(n):
    for j in range(len(A)):
        a, b = 0, j
        while dp[a][b] == 1:
            a += 1
            b += 1
            if a < len(B) and b < len(A): break
        if a == len(B):
            dyp.append(j)
for x in dyp:
    count = 0
    for t in m:
        if t[0] <= (x+1) <=t[1]:
            count += 1
    print(count)
